package com.walter.more_mysql.Controller;

import com.walter.more_mysql.dao.master.LocalMysql;
import com.walter.more_mysql.dao.second.Table30424;
import com.walter.more_mysql.model.Model;
import com.walter.more_mysql.model.T30424;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

/**
 * @ProjectName: more_mysql
 * @Package: com.walter.more_mysql.Controller
 * @ClassName: Test
 * @Description: java类作用描述
 * @Author: 唐朝
 * @CreateDate: 2019/1/18 16:42
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/1/18 16:42
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Component
@RestController
public class Test {
    @Resource
    @Autowired
    private Table30424 tDao;

    @Resource
    @Autowired
    private LocalMysql lDao;

    @RequestMapping("/test1")
    public void begin1() {
        List<Model> list = lDao.getData(0,20000);
        System.out.println("第一段开始时间为:" + new Date());
        for (int i = 0; i < list.size(); i++) {
            if (i % 1001 == 0) {
                System.out.println("一段完成1000个了" + new Date());
            }
            T30424 listData = tDao.getList(list.get(i).getOwnername());//作者
            Model model=new Model();
            model.setCount(list.get(i).getCount());
            model.setCreatime(list.get(i).getCreatime());
            model.setData(list.get(i).getData());
            model.setId(list.get(i).getId());
            model.setOwnername(list.get(i).getOwnername());
            model.setPcount(list.get(i).getPcount());
            model.setScount(list.get(i).getScount());
            model.setVcount(list.get(i).getVcount());
            if (listData==null)
                continue;
            if(list.get(i).getSource()!=null){
                model.setSource(listData.getCreator());
            }else {
                model.setSource(list.get(i).getSource());
            }
            lDao.saveData(model);

          //  lDao.addData(listData.getCreator(), listData.getOwnerName());

        }
        System.out.println("第一段结束时间为:" + new Date());
    }


   @RequestMapping("/test2")
    public void begin2() {
        List<T30424> list = lDao.getDatas(19999,20000);
        System.out.println("第二段条开始时间为:" + new Date());
        for (int i = 0; i < list.size(); i++) {
            if (i % 1001 == 0) {
                System.out.println("二段完成1000个了" + new Date());
            }
            T30424 listData = tDao.getList(list.get(i).getOwnerName());
            if (listData==null)
                continue;
            lDao.addData(listData.getCreator(), listData.getOwnerName());

        }
        System.out.println("第二段结束时间为:" + new Date());
    }

     /*
    @RequestMapping("/test3")
    public void begin3() {
        List<T30424> list = lDao.getData(39999,20000);
        System.out.println("第三段开始时间为:" + new Date());
        for (int i = 0; i < list.size(); i++) {
            if (i % 1001 == 0) {
                System.out.println("三段完成1000个了" + new Date());
            }
            T30424 listData = tDao.getList(list.get(i).getOwnerName());
            if (listData==null)
                continue;
            lDao.addData(listData.getCreator(), listData.getOwnerName());

        }
        System.out.println("第三段结束时间为:" + new Date());
    }

    @RequestMapping("/test4")
    public void begin4() {
        //List<T30424> list = lDao.getData(59999,20000);
        System.out.println("第四段开始时间为:" + new Date());
        for (int i = 0; i < list.size(); i++) {
            if (i % 1001 == 0) {
                System.out.println("四段完成1000个了" + new Date());
            }
            T30424 listData = tDao.getList(list.get(i).getOwnerName());
            if (listData==null)
                continue;
            lDao.addData(listData.getCreator(), listData.getOwnerName());

        }
        System.out.println("第四段结束时间为:" + new Date());
    }

    @RequestMapping("/test5")
    public void begin5() {
        List<T30424> list = lDao.getData(79999,30000);
        System.out.println("第五段开始时间为:" + new Date());
        for (int i = 0; i < list.size(); i++) {
            if (i % 1001 == 0) {
                System.out.println("五段完成1000个了" + new Date());
            }
            T30424 listData = tDao.getList(list.get(i).getOwnerName());
            if (listData==null)
                continue;
            lDao.addData(listData.getCreator(), listData.getOwnerName());

        }
        System.out.println("第五段结束时间为:" + new Date());
    }*/

}
